﻿using FPP.Models;
using NUnit.Framework;

namespace FPP.Tests.Models
{
    [TestFixture]
    public class BachelorGameTest
    {

        [Test]
        public void Isvalid()
        {
            Assert.IsTrue(true);
        }

        //complete: Create a Game - 
        //complete: should have a bachelor
        //complete: should have contestants
        //TODO: Added a round to the Game
        //TODO: Score a value for each round
        //TODO: What happened to each contestant in each round

        public static BachelorGame GetTestBachelorGame()
        {
            var bachelorGame = new BachelorGame(1) {Name = "The Bachelor 16"};

            return bachelorGame;
        }

        [TestFixture]
        public class GameReferences : BaseTest
        {
            [TestFixtureSetUp]
            public void Setup()
            {
                _context = new FakeFppEntities();
            }

            [Test]
            public void GameNeedsToHaveABachelor()
            {
                var repository = new FppRepository(_context);

                //Add Game to repo
                var bachelorGame = GetTestBachelorGame();
                repository.AddBachelorGame(bachelorGame);

                //Add Bachelor to repo
                var validBachelorPerson = new BachelorPerson { BachelorGameId = 1, IsBachelor = true, Name = "Ben" };
                repository.AddBachelorPerson(validBachelorPerson);

                var response = bachelorGame.Bachelor(repository);

                Assert.AreEqual(validBachelorPerson, response);
            }

            [Test]
            public void GameShouldHaveContestants()
            {
                var repository = new FppRepository(_context);

                //Add Game to repo
                var bachelorGame = GetTestBachelorGame();
                repository.AddBachelorGame(bachelorGame);

                var contestants = bachelorGame.Contestants(repository);

                Assert.IsTrue(contestants.Length == 0);

                //Add contestants to repo
                var validBachelorPerson = new BachelorPerson { BachelorGameId = 1, IsBachelor = false, Name = "Casey" };
                var validBachelorPerson2= new BachelorPerson { BachelorGameId = 1, IsBachelor = false, Name = "Courtney" };

                repository.AddBachelorPerson(validBachelorPerson);
                repository.AddBachelorPerson(validBachelorPerson2);

                contestants = bachelorGame.Contestants(repository);

                Assert.Greater(contestants.Length, 0);
            }
        }

        [TestFixture]
        public class AddAGame : BaseTest
        {
            [TestFixtureSetUp]
            public void AddAGameSetup()
            {
                _context = new FakeFppEntities();
            }


            [Test]
            public void GameShouldHaveAName()
            {
                var repository = new FppRepository(_context);

                var bachelorGame = new BachelorGame(1);

                var response = repository.AddBachelorGame(bachelorGame);

                Assert.AreEqual(false, response);

                bachelorGame.Name = "The Bachelor 16";

                response = repository.AddBachelorGame(bachelorGame);

                Assert.AreEqual(true, response);
            }

        }

    }
}

